import pygame
import sys

#Iniciar pygame
pygame.init()

# Configurar la ventana
ancho = 500
alto = 312
ventana = pygame.display.set_mode((ancho, alto))
NARANJA=(232, 97, 0)
ventana.fill(NARANJA)
pygame.display.set_caption('Hola Pato!')


granja = pygame.image.load("img/granja.jpeg")
x,y = 0,0

#Pintar casa en coordenadas (x,y) de la ventana
ventana.blit(granja, [x,y])
pygame.display.flip()

mary = pygame.image.load("img/mary.png")
x_mary,y_mary = 200,150

ventana.blit(mary, [x_mary,y_mary])
pygame.display.flip()

# Configurar el tipo de letra
tamanio = 48
fuente = pygame.font.SysFont(None, tamanio)
 
# Configurar el texto
texto = fuente.render('Hello duck!', True, NARANJA)
textoRect = texto.get_rect()
textoRect.centerx = ventana.get_rect().centerx
textoRect.centery = ventana.get_rect().centery
ventana.blit(texto, textoRect)
pygame.display.flip()
 # Bucle de eventos
while True:
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			pygame.quit()
			sys.exit()
        if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    ventana.blit (granja, [x,y])
                    x_mary = x_mary - 1
                    ventana.blit(mary, [x_mary,y_mary])
                    pygame.display.flip()                                 

                if event.key == pygame.K_UP:
                    ventana.blit (granja, [x,y])
                    y_mary = y_mary - 1
                    ventana.blit(mary, [x_mary,y_mary])
                    pygame.display.flip()
                               
                if event.key == pygame.K_RIGHT:
                    ventana.blit (granja, [x,y])
                    x_mary = x_mary + 1
                    ventana.blit(mary, [x_mary,y_mary])
                    pygame.display.flip()
              
                if event.key == pygame.K_DOWN:
                    ventana.blit (granja, [x,y])
                    y_mary = y_mary + 1
                    ventana.blit(mary, [x_mary,y_mary])
                    pygame.display.flip() 
